package com.riant.day08;

/**
 * @Classname Demo04
 * @Description TODO
 * @Date 2021/3/24 10:38
 * @Created by 张斌
 */
public class Demo04 implements Runnable{
    private volatile int ticket=10;

    @Override
    public void run() {
        while(true){
            if(ticket<=0){
                break;
            }
            System.out.println(Thread.currentThread().getName() +"拿了第"+ticket--+"张票");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Demo04 demo04=new Demo04();
        new Thread(demo04,"小王").start();
        new Thread(demo04,"老师").start();
        new Thread(demo04,"黄牛").start();
    }
}
